$serverName = "SQLServerTrainingKitAlias"
$version = "1.0.0.0"
$databasename = "CaseLoad"
$applicationname = "CaseLoad"
$description = "This is the CaseLoad sample data-tier application"

$server = New-Object Microsoft.SqlServer.Management.Smo.Server($serverName)
$server.ConnectionContext.LoginSecure = $true
$server.ConnectionContext.Connect()

$registerunit = New-Object Microsoft.SqlServer.Management.Dac.DacExtractionUnit($server, $databasename, $applicationname, $version)
$registerunit.Description = $description
$registerunit.Register()

if (!$?)
{
	throw "An error has occurred trying to register the $applicationname data-tier application"
}
else
{
	Write-Host "The $applicationname data-tier application was successfully registered"
}

$databasename = "CaseTrack"
$applicationname = "CaseTrack"
$description = "This is the CaseTrack sample data-tier application"

$registerunit = New-Object Microsoft.SqlServer.Management.Dac.DacExtractionUnit($server, $databasename, $applicationname, $version)
$registerunit.Description = $description
$registerunit.Register()


if (!$?)
{
	throw "An error has occurred trying to register the $applicationname data-tier application"
}
else
{
	Write-Host "The $applicationname data-tier application was successfully registered"
}